package com.mantru.iotpot.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import androidx.annotation.Nullable;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * 菜谱管理表（后台编辑的）
 * 作者： cmh
 * 日期： 2022/12/19
 */

public class t_vegetable_info
{
    //push_src  0系统下载的，2微调过的，3本地录制或新增的
    //2025.06.20 要求实现全部菜谱同步到云端保存，增加了3个字段
    //server_vegetable_id   云端的菜谱id，值为0时表示还没有保存到云端
    //update_time  最后更新的时间，10位时间截
    //is_need_sendtoserver  是否需要发送给云端，1是、0否
    public String table_name = "t_vegetable_info";
    public String company_id,parent_company_id,vegetable_id,vegetable_name,work_time,user_work_qty,sort_index,update_time,push_src,face_image_url,spec_data,from_vegetable_id="0",last_work_time,firsh_char;
    public String search_data = "", begin_time = "", end_time = "", server_vegetable_id = "0", is_need_sendtoserver = "0";
    public String create_sql = "create table t_vegetable_info(vegetable_id integer primary key, company_id integer,parent_company_id integer, vegetable_name text, face_image_url text, work_time text, user_work_qty integer, sort_index integer, update_time text, push_src integer, last_work_time integer, from_vegetable_id integer, spec_data text, firsh_char text, server_vegetable_id integer, is_need_sendtoserver integer)";
    public String drop_sql = "drop table t_vegetable_info";
    public String entity_sql = "select * from t_vegetable_info where vegetable_id=?";
    public String entity_sql2 = "select * from t_vegetable_info where (company_id=0 or company_id=?) and parent_company_id=? and vegetable_name=?";
    public String entity_from_sql = "select * from t_vegetable_info where from_vegetable_id=?";
    public String list_sql1 = "select vegetable_id,vegetable_name,face_image_url from t_vegetable_info order by last_work_time desc, sort_index";
    public String list_sql2 = "select vegetable_id,vegetable_name,face_image_url from t_vegetable_info order by last_work_time desc, sort_index";
    public String list_sql31 = "select vegetable_id,vegetable_name,face_image_url from t_vegetable_info where (company_id=0 and parent_company_id=0) or company_id=? or (company_id=0 and parent_company_id=?) order by user_work_qty desc, sort_index limit ";
    public String list_sql30 = "select vegetable_id,vegetable_name,face_image_url from t_vegetable_info where (company_id=0 and parent_company_id=0) or company_id=? or (company_id=0 and parent_company_id=?) order by last_work_time desc, sort_index limit ";
    public String update_work_sql = "update t_vegetable_info set user_work_qty=user_work_qty+1, last_work_time=? where vegetable_id=?";
    public String update_time_sql = "update t_vegetable_info set update_time=?, last_work_time=? where vegetable_id=?";
    public String max_sql = "select ifnull(max(vegetable_id),0) as vegetable_id from t_vegetable_info";
    public String update_sql = "update t_vegetable_info set vegetable_name=?, face_image_url=?, update_time=?, last_work_time=?, spec_data=?, firsh_char=? where vegetable_id=?";
    public String update_time_and_qty_sql = "update t_vegetable_info set work_time=? where vegetable_id=?";
    public String update_spec_sql3 = "update t_vegetable_info set spec_data=?, face_image_url=?, update_time=?, is_need_sendtoserver=? where vegetable_id=?";
    public String update_save2server_sql = "update t_vegetable_info set is_need_sendtoserver=0, server_vegetable_id=? where vegetable_id=?";
    public String delete_sql = "delete from t_vegetable_info where vegetable_id=?";
    public String exists_sql1 = "select vegetable_id from t_vegetable_info where ((company_id=0 and parent_company_id=0) or company_id=? or (company_id=0 and parent_company_id=?)) and vegetable_name=?";
    public String exists_sql2 = "select vegetable_id from t_vegetable_info where ((company_id=0 and parent_company_id=0) or company_id=? or (company_id=0 and parent_company_id=?)) and vegetable_id<>? and vegetable_name=?";
    public String exists_sql3 = "select vegetable_id from t_vegetable_info from_vegetable_id=?";
    public String search_sql1 = "select vegetable_id,vegetable_name,face_image_url from t_vegetable_info where ((company_id=0 and parent_company_id=0) or company_id=? or (company_id=0 and parent_company_id=?)) and vegetable_name like '%%search_data%%' order by last_work_time, sort_index, vegetable_id limit ";
    public String search_sql2 = "select vegetable_id,vegetable_name,face_image_url from t_vegetable_info where ((company_id=0 and parent_company_id=0) or company_id=? or (company_id=0 and parent_company_id=?)) and vegetable_name like '%%search_data%%' %search_char% order by vegetable_name, last_work_time, sort_index, vegetable_id limit ";
    public String search_sql3 = "select vegetable_id,vegetable_name,face_image_url from t_vegetable_info where ((company_id=0 and parent_company_id=0) or company_id=? or (company_id=0 and parent_company_id=?)) and push_src in(2,3) and vegetable_name like '%%search_data%%' order by last_work_time, sort_index, vegetable_id desc limit ";
    public String delete_sql1 = "delete from t_vegetable_info where ((company_id=0 and parent_company_id=0) or company_id=? or (company_id=0 and parent_company_id=?)) and vegetable_name=?";
    public String delete_sql2 = "delete from t_vegetable_info where ((company_id=0 and parent_company_id=0) or company_id=? or (company_id=0 and parent_company_id=?)) and vegetable_id<>? and vegetable_name=?";
    public String delete_sql3 = "delete from t_vegetable_info where ((company_id=0 and parent_company_id=0) or company_id=? or (company_id=0 and parent_company_id=?)) and vegetable_id=?";

    public String[] GetUpdateSpecValues3()
    {
        String[] values = new String[5];
        values[0] = spec_data;
        values[1] = face_image_url;
        values[2] = update_time;
        values[3] = is_need_sendtoserver;
        values[4] = vegetable_id;
        return values;
    }

    public String[] GetDeleteValues1()
    {
        String[] values = new String[3];
        values[0] = company_id;
        values[1] = parent_company_id;
        values[2] = vegetable_name;
        return values;
    }

    public String[] GetDeleteValues2()
    {
        String[] values = new String[4];
        values[0] = company_id;
        values[1] = parent_company_id;
        values[2] = vegetable_id;
        values[3] = vegetable_name;
        return values;
    }

    public String[] GetExistsValues1()
    {
        String[] values = new String[3];
        values[0] = company_id;
        values[1] = parent_company_id;
        values[2] = vegetable_name;
        return values;
    }

    public String[] GetExistsValues2()
    {
        String[] values = new String[4];
        values[0] = company_id;
        values[1] = parent_company_id;
        values[2] = vegetable_id;
        values[3] = vegetable_name;
        return values;
    }

    public String[] GetDeleteValues3()
    {
        String[] values = new String[3];
        values[0] = company_id;
        values[1] = parent_company_id;
        values[2] = vegetable_id;
        return values;
    }

    public String[] GetExistsValues3()
    {
        String[] values = new String[1];
        values[0] = from_vegetable_id;
        return values;
    }

    public String[] GetEntityValues()
    {
        String[] values = new String[1];
        values[0] = vegetable_id;
        return values;
    }

    public String[] GetEntityFromValues()
    {
        String[] values = new String[1];
        values[0] = from_vegetable_id;
        return values;
    }

    public String[] GetDeleteValues()
    {
        String[] values = new String[1];
        values[0] = vegetable_id;
        return values;
    }

    public String[] GetUpdateTimeAndQtyValues()
    {
        String[] values = new String[2];
        values[0] = work_time;
        values[1] = vegetable_id;
        return values;
    }

    public String[] GetUpdateValues()
    {
        String[] values = new String[7];
        values[0] = vegetable_name;
        values[1] = face_image_url;
        values[2] = update_time;
        values[3] = last_work_time;
        values[4] = spec_data;
        values[5] = firsh_char;
        values[6] = vegetable_id;
        return values;
    }

    public String[] GetUpdateSend2ServerValues()
    {
        String[] values = new String[2];
        values[0] = server_vegetable_id;
        values[1] = vegetable_id;
        return values;
    }

    public String[] GetUpdateWorkValues()
    {
        String[] values = new String[2];
        values[0] = last_work_time;
        values[1] = vegetable_id;
        return values;
    }

    public String[] GetUpdateTimeValues()
    {
        String[] values = new String[3];
        values[0] = update_time;
        values[1] = last_work_time;
        values[2] = vegetable_id;
        return values;
    }

    public String[] GetList1Values()
    {
        String[] values = new String[0];
        return values;
    }

    public String[] GetList2Values()
    {
        String[] values = new String[0];
        return values;
    }

    public String[] GetList3Values()
    {
        String[] values = new String[2];
        values[0] = company_id;
        values[1] = parent_company_id;
        return values;
    }

    public ContentValues GetInsertContentValues()
    {
        ContentValues cv = new ContentValues();
        cv.put("vegetable_id", vegetable_id);
        cv.put("company_id", company_id);
        cv.put("parent_company_id", parent_company_id);
        cv.put("vegetable_name", vegetable_name);
        cv.put("work_time", work_time);
        cv.put("user_work_qty", user_work_qty);
        cv.put("sort_index", sort_index);
        cv.put("update_time", update_time);
        cv.put("face_image_url", face_image_url);
        cv.put("push_src", push_src);
        cv.put("face_image_url", face_image_url);
        cv.put("spec_data", spec_data);
        cv.put("from_vegetable_id", from_vegetable_id);
        cv.put("last_work_time", last_work_time);
        cv.put("firsh_char", firsh_char);
        cv.put("server_vegetable_id", server_vegetable_id);
        cv.put("is_need_sendtoserver", is_need_sendtoserver);
        return cv;
    }

    public String[] GetSearch1Values()
    {
        String[] values = new String[2];
        values[0] = company_id;
        values[1] = parent_company_id;
        return values;
    }

    public String[] GetSearch2Values()
    {
        String[] values = new String[2];
        values[0] = company_id;
        values[1] = parent_company_id;
        return values;
    }

    public String[] GetSearch3Values()
    {
        String[] values = new String[2];
        values[0] = company_id;
        values[1] = parent_company_id;
        return values;
    }


}
